#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int tt,p[maxn],sum[maxn],t[maxn],cppp[maxn];
bool bb[maxn];
struct node{
    int d,v,a;
};
node cp[maxn];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>tt;
    while(tt--){
        int n,m,l,k,ans=0,s=0,maxx=0;
        cin>>n>>m>>l>>k;
        for(int i=1;i<=n;i++)
        cin>>cp[i].d>>cp[i].v>>cp[i].a;
        for(int i=1;i<=m;i++) cin>>p[i];
        for(int i=1;i<=n;i++){
            bool flag=false;
            int xx=1;
            for(int j=1;j<=m;j++){
                if(cp[i].d>p[j]) continue;
                int ss=p[j]-cp[i].d;
                double x=sqrt(cp[i].v*cp[i].v+2*cp[i].a*ss);
                if(x>(double)k){
                    if(xx==1) xx=0;
                    if(!cppp[p[j]]){
                        cppp[p[j]]=i;
                        xx=3;
                        s++;
                    }
                    else if(cppp[p[j]]&&cppp[p[j]]!=i){
                        cppp[p[j]]=i;
                        if(!bb[p[j]]) s--;
                        bb[p[j]]=1;
                    }
                    flag=true;
                    t[j]++;
                    if(t[j]>maxx){
                        maxx=t[j];
                    }
                }
            }
        if(!xx) s++;
        if(flag) ans++;
        }
        for(int i=1;i<=m;i++){
            if(cppp[p[i]]==0) s++;
        }
        cout<<ans<<" "<<s<<endl;
        memset(t,0,sizeof(t));
        memset(cppp,0,sizeof(cppp));
    }
    return 0;
}
